@extends('admin.common.main')

@section('cnt')

    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 用户中心 <span class="c-gray en">&gt;</span> 用户管理 <a class="btn btn-success radius r " style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    {{-- 消息提示 --}}
    @include('admin.common.msg')
    <div class="page-container">
    <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l">
            <a href="javascript:;" onclick="delAll()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
            <a href="javascript:;" onclick="admin_add('添加预约','{{ route('admin.notice.create') }}','800','500')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加预约</a></span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-hover table-bg table-sort">
            <thead>
            <tr class="text-c">

                <th width="25"><input type="checkbox" name="" value=""></th>
                <th width="30">ID</th>
                <th width="100">房东</th>
                <th width="40">租客</th>
                <th width="40">时间</th>
                <th width="40">状态</th>
                <th width="90">消息内容</th>
                <th width="130">加入时间</th>
                <th width="100">操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($data as $val)
                <tr class="text-c">
                    <td><input type="checkbox" value="{{ $val->id }}" name="id[]"></td>
                    <td>{{ $val->id }}</td>
                    <td>{{ $val->owner->name }}</td>
                    <td>{{ $val->renting_id }}</td>
                    <td>{{ $val->dtime }}</td>
                    <td>{{ $val->status }}</td>
                    <td>{{ $val->cnt }}</td>
                    <td>{{ $val->created_at }}</td>
                    <td class="td-manage">
                        <a title="编辑" href="javascript:;" onclick="admin_edit('用户修改','{{route('admin.user.edit',$val)}}','800','500')"  class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                        <a title="删除" data-href="{{ route('admin.notice.destroy',$val) }}" class="ml-5 delbtn" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
</div>
@endsection

@section('js')
    <script>
        var table = $('.table-sort').DataTable({
            columnDefs:[
                //索引不排序;
                {targets:[0,8],orderable:false}
            ]
        })
        /*管理员-增加*/
        function admin_add(title,url,w,h){
            layer_show(title,url,w,h);
        }
        function user_role(title,url,w,h){
            layer_show(title,url,w,h);
        }
        /*管理员-修改*/
        function admin_edit(title,url,w,h){
            layer_show(title,url,w,h);
        }
        /*个人-修改*/
        function admin_myedit(title,url,w,h){
            layer_show(title,url,w,h);
        }
        del()
        table.on( 'draw', function () {
            del();
        } );



        //删除操作函数封装
        const _token = "{{ csrf_token() }}";
        function  del() {

            $('.delbtn').click(function(){
                url = $(this).attr("data-href");
                $.ajax({
                    url,
                    data:{_token},
                    type:'DELETE',
                    dataType:'json'
                }).then(({status,msg})=>{
                    if(status == 0){
                        layer.msg(msg,{time:1000,icon:1},()=>{
                            $(this).parents('tr').remove();
                        })
                    }else{
                        layer.msg(respond,{time:1000,icon:2})
                    }
                })
                return false;
            })
        }
        //全选删除
        function delAll() {
            layer.confirm('确认删除所选用户吗',{
                btn:['确定','取消']
            },()=>{
                //选择的用户
                let ids = $('input[name="id[]"]:checked');
                //删除的id
                let id = [];
                $.each(ids,(key,val)=>{
                    id.push(val.value);
                });
                if(id.length>0){
                    $.ajax({
                        url:"{{ route('admin.user.delAll') }}",
                        data:{id,_token},
                        type:'DELETE',
                    }).then(({status,msg})=>{
                        if(status == 0){
                            layer.msg(msg,{time:1500,icon:1},()=>{
                                location.reload();
                            })
                        }
                    })
                }else{
                    layer.msg('请勾选删除的用户',{time:1500,icon:2});
                }
            })
        }
    </script>
@endsection


